#!/bin/bash
#condition-control.sh

if [[ 7 > 3 ]] && [[ 5 > 4 ]]; then
	echo "yes"
else
	echo "no"
fi

comment_line="#Comment line"
content_line="Hello Content"
line="Line"

result=$(expr "$comment_line" : '^#.*')
echo "result = ${result}"
if [[ $(expr "$comment_line" : '#.*') -gt 0 ]]; then
	echo "comment_line 注释内容"
else
	echo "comment_line 其他内容"
fi

echo "========="

result=$(expr "$content_line" : '^#.*')
echo "result = ${result}"
if [[ $(expr "$content_line" : '#.*') -gt 0 ]]; then
	echo "content_line 注释内容"
else
	echo "content_line 其他内容"
fi

# re='^#.*'
# result=[[ "$content_line" =~ $re ]]
# echo "result = ${result}"
# if [[ "$content_line" =~ $re ]]; then
# 	echo "content_line 注释内容"
# else
# 	echo "content_line 其他内容"
# fi


echo ""
echo "=~ 运算符"
strA="helloworld"
strB="low"
if [[ $strA =~ $strB ]]
then
  echo "包含"
else
  echo "不包含"
fi

strA="@property (nonatomic, strong) NSString* invitationCode;"
strB="\*"
if [[ $strA =~ $strB ]]
then
  echo "${strA}包含${strB}"
else
  echo "${strA}不包含${strB}"
fi

strA="@property (nonatomic, strong) NSInteger invitationCode;"
strB="\*"
# check_result=[[ ${strA} =~ "\*" ]]
# echo "check_result = ${check_result}"
if [[ $strA =~ "\*" ]]; then
  echo "${strA}包含${strB}"
else
  echo "${strA}不包含${strB}"
fi

keywords=("window" "helloworld" "test")
for (( i = 0; i < ${#keywords[@]}; i++ )); do
	word=${keywords[$i]}
	grep_result=$(grep ${word} Config.cfg)
	echo "grep_result = >>${grep_result}<<"
	if [[ -n ${grep_result} ]]; then
		echo "--${word}--存在配置文件中"
	else
		echo "--${word}--XXX不存在配置文件中"
	fi
done


echo ""
echo "end"